﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Wicresoft.RDW.Presentation;

namespace Wicresoft.RDW.Report
{
    public partial class CreditScore : BasePage_BackEnd
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            PagerControll.PageChange += new Wicresoft.RDW.UserControls.PagerControl.PageRefresh(PagerControll_PageChange);
            if (!this.IsPostBack)
            {
                InitControlResource();
                PagerControll_PageChange(0);
            }

        }

        public override void InitControlResource()
        {
            int i = 0;
            GvCreditScore.Columns[i++].HeaderText = Resources.NameResource.No;
            GvCreditScore.Columns[i++].HeaderText = Resources.ManageResource.mgr_lblDept;
            GvCreditScore.Columns[i++].HeaderText = Resources.ManageResource.mgr_lblPlatform;
            GvCreditScore.Columns[i++].HeaderText = Resources.ManageResource.mgr_lblCreditScore;

            //var creditScore = DepartmentPresent.GetList().OrderBy(g => g.CreditScore).ToList();
            //GvCreditScore.DataSource = creditScore;
            //GvCreditScore.DataBind();
        }

        void PagerControll_PageChange(int pageIndex)
        {
            // todo orderby issue
            var creditScore = DepartmentPresent.GetPaged(pageIndex, PagerControll.PageSize, g => g.CreditScore,true);
            GvCreditScore.DataSource = creditScore;
            GvCreditScore.DataBind();
            PagerControll.IntialProperties(creditScore.TotalCount);
        }

        protected void GvCreditScore_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                int i = 0;
                e.Row.Cells[i++].Text = (e.Row.RowIndex + 1 + (PagerControll.CurrentPageIndex) * PagerControll.PageSize).ToString();
            }
        }
    }
}